package main.menu;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;

import main.staff.CreateTypesSql;
import main.util.SqlConstants;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class OperatorButton {

	public static FileWriter module,menu,authelement,delete;
	
	public static Sheet sheet;
	
	public static void main(String[] args) {
		InputStream inp;
		try {
			inp = new FileInputStream("E:/1.xlsx");
			//InputStream inp = new FileInputStream("workbook.xlsx");
			
			Workbook wb = WorkbookFactory.create(inp);
			sheet = wb.getSheetAt(2);
			
			String[] name=sheet.getSheetName().split("-");
			 module = new FileWriter("E:/"+name[0]+"t_ucp_module.sql");
			 menu= new FileWriter("E:/"+name[0]+"t_ucp_menu.sql");
			 authelement=new FileWriter("E:/"+name[0]+"t_ucp_authelement.sql");
			 delete=new FileWriter("E:/"+name[0]+"删除.sql");
			
			 SqlConstants.topWriteHead(module);
			 SqlConstants.topWriteHead(menu);
			 SqlConstants.topWriteHead(authelement);
			
			 CreateMenuSql cms=new CreateMenuSql(module, menu, authelement, sheet,"getMenuSqlCRMSSO");//getMenuSql,getMenuSqlCRMSSO
			 cms.setDelete(delete);
			 //cms.setDISPLAYNO(22);
			cms.setDISPLAYNO(new Integer(name[1]));
			//cms.setDISPLAYNO(31);
			 
			 cms.operateSheet("");
			
			 module.write("commit;\n");menu.write("commit;\n");authelement.write("commit;\n");delete.write("commit;\n");
			 
			 module.close();
			 menu.close();
			 authelement.close();
			 delete.close();
			 
			 
			 FileOutputStream fos=new FileOutputStream(new File("E:/3.xlsx"));
			 wb.write(fos);
			 wb.cloneSheet(3);
			 //wb.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			
		}
	}

}
